clc;
clear;
% 1. 读取CSV文件（使用逗号分隔）
data = readtable('faults.csv', 'Delimiter', ',');

% 2. 打印实际列名以确认
disp('实际列名:');
disp(data.Properties.VariableNames);

% 3. 定义特征和标签列名
feature_columns = {
    'X_Minimum', 'X_Maximum', 'Y_Minimum', 'Y_Maximum', 'Pixels_Areas', ...
    'X_Perimeter', 'Y_Perimeter', 'Sum_of_Luminosity', 'Minimum_of_Luminosity', ...
    'Maximum_of_Luminosity', 'Length_of_Conveyer', 'TypeOfSteel_A300', ...
    'TypeOfSteel_A400', 'Steel_Plate_Thickness', 'Edges_Index', 'Empty_Index', ...
    'Square_Index', 'Outside_X_Index', 'Edges_X_Index', 'Edges_Y_Index', ...
    'Outside_Global_Index', 'LogOfAreas', 'Log_X_Index', 'Log_Y_Index', ...
    'Orientation_Index', 'Luminosity_Index', 'SigmoidOfAreas'};

label_columns = {
    'Pastry', 'Z_Scratch', 'K_Scatch', 'Stains', ...
    'Dirtiness', 'Bumps', 'Other_Faults'};

% 4. 检查列名是否存在
all_vars = data.Properties.VariableNames;
missing_features = setdiff(feature_columns, all_vars);
missing_labels = setdiff(label_columns, all_vars);

if ~isempty(missing_features)
    error('缺失特征列: %s', strjoin(missing_features, ', '));
end
if ~isempty(missing_labels)
    error('缺失标签列: %s', strjoin(missing_labels, ', '));
end

% 5. 提取特征和标签数据
features = data{:, feature_columns};
labels = data{:, label_columns};
[~, max_labels] = max(labels, [], 2);

% 合并标签和特征
data = horzcat(max_labels, features);

% 随机打乱数据
random_indices = randperm(size(data, 1));
data_random = data(random_indices, :);


a = 1;